/*
 * Copyright (c) 2019. seven studio. @chengdu
 * seven studio in chengdu by lb
 * this project for snmp tool
 */

package com.xlx.openLink.threadtask.workservice;

import com.xlx.openLink.service.AlarmService;
import com.xlx.openLink.service.DeviceService;
import com.xlx.openLink.service.SpeedService;
import com.xlx.openLink.threadtask.workthread.SearchSpeedThread;
import com.xlx.openLink.uitls.Commuitls;
import com.xlx.openLink.vo.DevicePortVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class SearchSpeedService {

    @Autowired
    private DeviceService deviceService;
    @Autowired
    private SpeedService speedService;
    @Autowired
    private AlarmService alarmService;

    public void SearchSpeed(List<DevicePortVO> devicePortVOList) throws Exception {

        //创建线程池
        ExecutorService executorService = new ThreadPoolExecutor(20, 40, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue(99999));

        //任务分组
        List<List> listList = Commuitls.spList(devicePortVOList,5);

        for (List<DevicePortVO> list : listList) {
            executorService.execute(new SearchSpeedThread(list,deviceService,speedService,alarmService));
        }
        executorService.shutdown();
        while (true) {
            if (executorService.isTerminated()) {
                log.info("计算网速执行成功");
                break;
            }
        }

    }


}
